//#define _CRT_SECURE_NO_WARNINGS 1
///**
// * Definition for singly-linked list.
// * struct ListNode {
// *     int val;
// *     struct ListNode *next;
// * };
// */
//struct ListNode* reverseList(struct ListNode* head) {
//
//    if (head == NULL)
//    {
//        return NULL;
//    }
//
//    struct ListNode* n1 = NULL;
//    struct ListNode* n2 = head;
//    struct ListNode* n3 = n2->next;
//
//    while (n2)
//    {
//        n3 = n2->next;
//        n2->next = n1;
//        n1 = n2;
//        n2 = n3;
//
//    }
//    return n1;
//
//
//
//
//
//}


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* middleNode(struct ListNode* head) {

    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {

        slow = slow->next;

        fast = fast->next->next;



    }
    return slow;




}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {

    if (head == NULL)
    {
        return NULL;
    }
    struct ListNode* n = head;
    struct ListNode* newhead = NULL;
    struct ListNode* next = NULL;


    do
    {
        next=n->next;


        n->next = newhead;
        newhead = n;
        n = next;
    } while (n);


    return newhead;




}